package 获取随机数;

//猜数字

import java.util.Random;
import java.util.Scanner;

public class test02 {
    public static void main(String[] args) {
        Random r = new Random();
        int number = r.nextInt(100) + 1;
        int count = 0;
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入你猜的数字");
            int guessnumber = sc.nextInt();

            if (number < guessnumber) {
                count += 1;
                System.out.println("你猜的大了");
            } else if (number > guessnumber) {
                count += 1;
                System.out.println("你猜的小了");
            } else {
                count += 1;
                System.out.println("恭喜你猜对了;" + "共猜了" + count + "次");

                break;
            }
        }
    }
}
